{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xlyptNJ2ICnN"
      },
      "source": [
        "# Fooooooooooooooocus\n",
        "Colab NoteBook Created by [licyk](https://github.com/licyk)\n",
        "\n",
        "Jupyter Notebook 仓库：[licyk/sd-webui-all-in-one](https://github.com/licyk/sd-webui-all-in-one)\n",
        "\n",
        "这是适用于 [Colab](https://colab.research.google.com) 部署 [Fooocus](https://github.com/lllyasviel/Fooocus) 的 Jupyter Notebook，使用时请按顺序执行 Jupyter Notebook 单元。\n",
        "\n",
        "Colab 链接：<a href=\"https://colab.research.google.com/github/licyk/sd-webui-all-in-one/blob/main/notebook/fooocus_colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
        "\n",
        "## 功能\n",
        "1. 环境配置：配置安装的 PyTorch 版本、内网穿透的方式，并安装 [Fooocus](https://github.com/lllyasviel/Fooocus)，默认设置下已启用`配置环境完成后立即启动 Fooocus`选项，则安装完成后将直接启动 Fooocus，并显示访问地址。\n",
        "2. 下载模型：下载可选列表中的模型（可选）。\n",
        "3. 自定义模型下载：使用链接下载模型（可选）。\n",
        "4. 启动 Fooocus：启动 Fooocus，并显示访问地址。\n",
        "\n",
        "\n",
        "## 使用\n",
        "1. 在 Colab -> 代码执行程序 > 更改运行时类型 -> 硬件加速器 选择`GPU T4`或者其他 GPU。\n",
        "2. `环境配置`单元中的选项通常不需要修改，保持默认即可。\n",
        "3. 运行`环境配置`单元，默认设置下已启用`配置环境完成后立即启动 Fooocus`选项，则环境配置完成后立即启动 Fooocus，此时将弹出 Google Drive 授权页面，根据提示进行操作。配置完成后将启动 Fooocus，Fooocus 的访问地址可在日志中查看。\n",
        "4. 如果未启用`配置环境完成后立即启动 Fooocus`选项，需要运行`启动 Fooocus`单元，此时将弹出 Google Drive 授权页面，根据提示进行操作。配置完成后将启动 Fooocus，Fooocus 的访问地址可在日志中查看。\n",
        "5. 提示词查询工具：[SD 绘画提示词查询](https://licyk.github.io/t/tag)\n",
        "\n",
        "## 提示\n",
        "1. Colab 在关机后将会清除所有数据，所以每次重新启动时必须运行`环境配置`单元才能运行`启动 Fooocus`单元。\n",
        "2. [Ngrok](https://ngrok.com) 内网穿透在使用前需要填写 Ngrok Token，可在 [Ngrok](https://ngrok.com) 官网获取。\n",
        "3. [Zrok](https://zrok.io) 内网穿透在使用前需要填写 Zrok Token, 可在 [Zrok](https://docs.zrok.io/docs/getting-started) 官网获取。\n",
        "4. 每次启动 Colab 后必须运行`环境配置`单元，才能运行`启动 Fooocus`单元启动 Fooocus。\n",
        "5. 其他功能有自定义模型下载等功能，根据自己的需求进行使用。\n",
        "6. 运行`启动 Fooocus`时将弹出 Google Drive 访问授权提示，根据提示进行授权。授权后，使用 Fooocus 生成的图片将保存在 Google Drive 的`fooocus_output`文件夹中。\n",
        "7. Gradio 的内网穿透地址可在启动 Fooocus 后日志中的`Running on public URL`查看。\n",
        "8. Fooocus 启动预设文件可自行编写，并上传到 Github 或者其他平台并获取下载链接后，可以替换`Fooocus 启动预设文件地址`中的链接，进行环境配置时将使用该预设文件启动 Fooocus。预设文件可自行下载下来进行参考，其他有关说明可阅读：[Customization - lllyasviel/Fooocus](https://github.com/lllyasviel/Fooocus?tab=readme-ov-file#customization)。\n",
        "9. 在`额外挂载目录设置`中可以挂载一些额外目录，如 LoRA 模型目录，挂载后的目录可在 Google Drive 的`fooocus_output`文件夹中查看和修改。可通过该功能在 Google Drive 上传模型并在 Fooocus 中使用。\n",
        "10. 默认挂载以下目录到 Google Drive，可在 Google Drive 的`fooocus_output`文件夹中上传和修改文件：`outputs`, `presets`, `language`, `wildcards`, `config.txt`"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "VjYy0F2gZIPR"
      },
      "outputs": [],
      "source": [
        "#@title 👇 环境配置\n",
        "# SD WebUI All In One 功能初始化部分, 通常不需要修改\n",
        "# 如果需要查看完整代码实现, 可阅读: https://github.com/licyk/sd-webui-all-in-one/blob/main/sd_webui_all_in_one\n",
        "#################################################################################################################\n",
        "# SD_WEBUI_ALL_IN_ONE_URL, FORCE_DOWNLOAD_CORE 参数可根据需求修改, 通常保持默认即可\n",
        "SD_WEBUI_ALL_IN_ONE_URL = \"https://github.com/licyk/sd-webui-all-in-one@main\" # SD WebUI All In One 核心下载地址\n",
        "FORCE_DOWNLOAD_CORE = False # 设置为 True 时, 即使 SD WebUI All In One 已存在也会重新下载\n",
        "#################################################################################################################\n",
        "import os\n",
        "try:\n",
        "    _ = JUPYTER_ROOT_PATH  # type: ignore # noqa: F821\n",
        "except Exception:\n",
        "    JUPYTER_ROOT_PATH = os.getcwd()\n",
        "!python -c \"import sd_webui_all_in_one\" &> /dev/null && [ \"{FORCE_DOWNLOAD_CORE}\" != \"True\" ] || python -m pip install \"git+{SD_WEBUI_ALL_IN_ONE_URL}\"\n",
        "from sd_webui_all_in_one import logger, VERSION, FooocusManager\n",
        "logger.info(\"SD WebUI All In One 核心模块初始化完成, 版本: %s\", VERSION)\n",
        "\n",
        "#######################################################\n",
        "\n",
        "#@markdown ## Fooocus 核心配置选项\n",
        "#@markdown - Fooocus 分支仓库地址：\n",
        "FOOOCUS_REPO = \"https://github.com/lllyasviel/Fooocus\" #@param {type:\"string\"}\n",
        "#@markdown - Fooocus 启动预设文件地址：\n",
        "FOOOCUS_PRESET = \"https://github.com/licyk/sd-webui-all-in-one/raw/main/config/fooocus_config.json\" #@param {type:\"string\"}\n",
        "#@markdown - Fooocus 翻译文件下载地址：\n",
        "FOOOCUS_TRANSLATION = \"https://github.com/licyk/sd-webui-all-in-one/raw/main/config/fooocus_zh_cn.json\" #@param {type:\"string\"}\n",
        "#@markdown - Fooocus 依赖表名：\n",
        "FOOOCUS_REQUIREMENTS = \"requirements_versions.txt\" #@param {type:\"string\"}\n",
        "#@markdown - Fooocus 启动参数：\n",
        "FOOOCUS_LAUNCH_ARGS = \"--preset custom --language zh --async-cuda-allocation --disable-analytics --always-high-vram --always-download-new-model\" #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## PyTorch 组件版本选项：\n",
        "#@markdown - PyTorch：\n",
        "PYTORCH_VER = \"torch==2.8.0+cu126 torchvision==0.23.0+cu126 torchaudio==2.8.0+cu126\" #@param {type:\"string\"}\n",
        "#@markdown - xFormers：\n",
        "XFORMERS_VER = \"xformers==0.0.32.post2\" #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 包管理器选项：\n",
        "#@markdown - 使用 uv 作为 Python 包管理器\n",
        "USE_UV = True #@param {type:\"boolean\"}\n",
        "#@markdown - PyPI 主镜像源\n",
        "PIP_INDEX_MIRROR = \"https://pypi.python.org/simple\" #@param {type:\"string\"}\n",
        "#@markdown - PyPI 扩展镜像源\n",
        "PIP_EXTRA_INDEX_MIRROR = \"https://download.pytorch.org/whl/cu126\" #@param {type:\"string\"}\n",
        "#@markdown - PyPI 额外镜像源\n",
        "PIP_FIND_LINKS_MIRROR = \"\" #@param {type:\"string\"}\n",
        "#@markdown - PyTorch 镜像源\n",
        "PYTORCH_MIRROR = \"https://download.pytorch.org/whl/cu126\" #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 内网穿透选项：\n",
        "#@markdown - 使用 remote.moe 内网穿透\n",
        "USE_REMOTE_MOE = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 localhost.run 内网穿透\n",
        "USE_LOCALHOST_RUN = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 pinggy.io 内网穿透\n",
        "USE_PINGGY_IO = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 CloudFlare 内网穿透\n",
        "USE_CLOUDFLARE = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 Gradio 内网穿透\n",
        "USE_GRADIO = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 Ngrok 内网穿透（需填写 Ngrok Token，可在 [Ngrok](https://ngrok.com) 官网获取）\n",
        "USE_NGROK = True #@param {type:\"boolean\"}\n",
        "#@markdown - Ngrok Token\n",
        "NGROK_TOKEN = \"\"  #@param {type:\"string\"}\n",
        "#@markdown - 使用 Zrok 内网穿透（需填写 Zrok Token，可在 [Zrok](https://docs.zrok.io/docs/getting-started) 官网获取）\n",
        "USE_ZROK = True #@param {type:\"boolean\"}\n",
        "#@markdown - Zrok Token\n",
        "ZROK_TOKEN = \"\"  #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 快速启动选项：\n",
        "#@markdown - 配置环境完成后立即启动 Fooocus（并挂载 Google Drive）\n",
        "QUICK_LAUNCH = True #@param {type:\"boolean\"}\n",
        "#@markdown - 不重复配置环境（当重复运行环境配置时将不会再进行安装）\n",
        "NO_REPEAT_CONFIGURE_ENV = True #@param {type:\"boolean\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 其他选项：\n",
        "#@markdown - 预下载模型时使用的下载器\n",
        "MODEL_DOWNLOADER = \"mix\" #@param [\"aria2\", \"requests\", \"mix\"]\n",
        "#@markdown - 预下载模型时下载线程\n",
        "DOWNLOAD_MODEL_THREAD = 16 #@param {type:\"slider\", min:1, max:64, step:1}\n",
        "#@markdown - 清理无用日志\n",
        "CLEAR_LOG = True #@param {type:\"boolean\"}\n",
        "#@markdown - 检查可用 GPU\n",
        "CHECK_AVALIABLE_GPU = True #@param {type:\"boolean\"}\n",
        "#@markdown - 启用 TCMalloc 内存优化\n",
        "ENABLE_TCMALLOC = True #@param {type:\"boolean\"}\n",
        "#@markdown - 启用 CUDA Malloc 显存优化\n",
        "ENABLE_CUDA_MALLOC = True #@param {type:\"boolean\"}\n",
        "#@markdown - 更新内核\n",
        "UPDATE_CORE = True #@param {type:\"boolean\"}\n",
        "\n",
        "# @markdown ---\n",
        "##############################################################################\n",
        "# @markdown ## 额外挂载目录设置, 在启动时挂载目录到 Google Drive：\n",
        "EXTRA_LINK_DIR = []\n",
        "\n",
        "#@markdown - models/checkpoints 目录\n",
        "link_checkpoints_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/loras 目录\n",
        "link_loras_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/embeddings 目录\n",
        "link_embeddings_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/vae_approx 目录\n",
        "link_vae_approx_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/vae 目录\n",
        "link_vae_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/upscale_models 目录\n",
        "link_upscale_models_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/inpaint 目录\n",
        "link_inpaint_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/controlnet 目录\n",
        "link_controlnet_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/clip_vision 目录\n",
        "link_clip_vision_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/prompt_expansion 目录\n",
        "link_prompt_expansion_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/safety_checker 目录\n",
        "link_safety_checker_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - models/sam 目录\n",
        "link_sam_dir = False # @param {type:\"boolean\"}\n",
        "\n",
        "\n",
        "link_checkpoints_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/checkpoints\"})\n",
        "link_loras_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/loras\"})\n",
        "link_embeddings_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/embeddings\"})\n",
        "link_vae_approx_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/vae_approx\"})\n",
        "link_vae_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/vae\"})\n",
        "link_upscale_models_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/upscale_models\"})\n",
        "link_inpaint_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/inpaint\"})\n",
        "link_controlnet_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/controlnet\"})\n",
        "link_clip_vision_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/clip_vision\"})\n",
        "link_prompt_expansion_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/prompt_expansion\"})\n",
        "link_safety_checker_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/safety_checker\"})\n",
        "link_sam_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"models/sam\"})\n",
        "\n",
        "#######################################################\n",
        "\n",
        "INSTALL_PARAMS = {\n",
        "    \"torch_ver\": PYTORCH_VER or None,\n",
        "    \"xformers_ver\": XFORMERS_VER or None,\n",
        "    \"use_uv\": USE_UV,\n",
        "    \"pypi_index_mirror\": PIP_INDEX_MIRROR or None,\n",
        "    \"pypi_extra_index_mirror\": PIP_EXTRA_INDEX_MIRROR or None,\n",
        "    \"pypi_find_links_mirror\": PIP_FIND_LINKS_MIRROR or None,\n",
        "    # Colab 的环境暂不需要以下镜像源\n",
        "    # \"github_mirror\": GITHUB_MIRROR or None,\n",
        "    # \"huggingface_mirror\": HUGGINGFACE_MIRROR or None,\n",
        "    \"pytorch_mirror\": PYTORCH_MIRROR or None,\n",
        "    \"fooocus_repo\": FOOOCUS_REPO or None,\n",
        "    \"fooocus_requirements\": FOOOCUS_REQUIREMENTS or None,\n",
        "    \"fooocus_preset\": FOOOCUS_PRESET or None,\n",
        "    \"fooocus_translation\": FOOOCUS_TRANSLATION or None,\n",
        "    \"model_downloader\": MODEL_DOWNLOADER,\n",
        "    \"download_model_thread\": DOWNLOAD_MODEL_THREAD,\n",
        "    \"check_avaliable_gpu\": CHECK_AVALIABLE_GPU,\n",
        "    \"enable_tcmalloc\": ENABLE_TCMALLOC,\n",
        "    \"enable_cuda_malloc\": ENABLE_CUDA_MALLOC,\n",
        "    \"custom_sys_pkg_cmd\": None,\n",
        "    \"huggingface_token\": None,\n",
        "    \"modelscope_token\": None,\n",
        "    \"update_core\": UPDATE_CORE,\n",
        "}\n",
        "\n",
        "TUNNEL_PARAMS = {\n",
        "    \"use_ngrok\": USE_NGROK,\n",
        "    \"ngrok_token\": NGROK_TOKEN or None,\n",
        "    \"use_cloudflare\": USE_CLOUDFLARE,\n",
        "    \"use_remote_moe\": USE_REMOTE_MOE,\n",
        "    \"use_localhost_run\": USE_LOCALHOST_RUN,\n",
        "    \"use_gradio\": USE_GRADIO,\n",
        "    \"use_pinggy_io\": USE_PINGGY_IO,\n",
        "    \"use_zrok\": USE_ZROK,\n",
        "    \"zrok_token\": ZROK_TOKEN or None,\n",
        "    \"message\": \"##### Fooocus 访问地址 #####\",\n",
        "}\n",
        "\n",
        "FOOOCUS_PATH = \"/content/Fooocus\"\n",
        "try:\n",
        "    _ = fooocus_manager_has_init  # type: ignore # noqa: F821\n",
        "except Exception:\n",
        "    fooocus = FooocusManager(os.path.dirname(FOOOCUS_PATH), os.path.basename(FOOOCUS_PATH), port=7865)\n",
        "    fooocus_manager_has_init = True\n",
        "\n",
        "try:\n",
        "    _ = fooocus_has_init  # type: ignore # noqa: F821\n",
        "except Exception:\n",
        "    fooocus_has_init = False\n",
        "\n",
        "if NO_REPEAT_CONFIGURE_ENV:\n",
        "    if not fooocus_has_init:\n",
        "        fooocus.install(**INSTALL_PARAMS)\n",
        "        INIT_CONFIG = 1\n",
        "        fooocus_has_init = True\n",
        "        CLEAR_LOG and fooocus.clear_up()\n",
        "        logger.info(\"Fooocus 运行环境配置完成\")\n",
        "    else:\n",
        "        logger.info(\"检测到不重复配置环境已启用, 并且在当前 Colab 实例中已配置 Fooocus 运行环境, 不再重复配置 Fooocus 运行环境\")\n",
        "        logger.info(\"如需在当前 Colab 实例中重新配置 Fooocus 运行环境, 请在快速启动选项中取消不重复配置环境功能\")\n",
        "else:\n",
        "    fooocus.install(**INSTALL_PARAMS)\n",
        "    INIT_CONFIG = 1\n",
        "    CLEAR_LOG and fooocus.clear_up()\n",
        "    logger.info(\"Fooocus 运行环境配置完成\")\n",
        "\n",
        "if USE_GRADIO:\n",
        "    FOOOCUS_LAUNCH_ARGS = f\"{FOOOCUS_LAUNCH_ARGS} --share\"\n",
        "\n",
        "LAUNCH_CMD = fooocus.get_launch_command(FOOOCUS_LAUNCH_ARGS)\n",
        "\n",
        "if QUICK_LAUNCH:\n",
        "    logger.info(\"启动 Fooocus 中\")\n",
        "    os.chdir(FOOOCUS_PATH)\n",
        "    fooocus.check_env(\n",
        "        use_uv=USE_UV,\n",
        "        requirements_file=FOOOCUS_REQUIREMENTS,\n",
        "    )\n",
        "    fooocus.mount_drive(EXTRA_LINK_DIR)\n",
        "    fooocus.tun.start_tunnel(**TUNNEL_PARAMS)\n",
        "    logger.info(\"Fooocus 启动参数: %s\", FOOOCUS_LAUNCH_ARGS)\n",
        "    !{LAUNCH_CMD}\n",
        "    CLEAR_LOG and fooocus.clear_up()\n",
        "    logger.info(\"已关闭 Fooocus\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "ZWnei0cZwWzK"
      },
      "outputs": [],
      "source": [
        "#@title 👇 下载模型（可选）\n",
        "\n",
        "try:\n",
        "    _ = INIT_CONFIG\n",
        "except Exception:\n",
        "    raise Exception(\"未安装 Fooocus\")\n",
        "\n",
        "# 模型下载\n",
        "logger.info(\"下载模型中\")\n",
        "MODEL_LIST = []\n",
        "#@markdown 选择下载的模型：\n",
        "##############################\n",
        "\n",
        "sd_xl_base_1_0_0_9vae = False # @param {type:\"boolean\"}\n",
        "animapencilxl_v200 = False # @param {type:\"boolean\"}\n",
        "bluepencilxl_v401 = False # @param {type:\"boolean\"}\n",
        "anythingxl_xl = False # @param {type:\"boolean\"}\n",
        "abyssorangexlelse_v10 = False # @param {type:\"boolean\"}\n",
        "counterfeitxl_v1_0 = False # @param {type:\"boolean\"}\n",
        "animeillustdiffusion_v061 = False # @param {type:\"boolean\"}\n",
        "nekorayxl_v06w3 = False # @param {type:\"boolean\"}\n",
        "animagine_xl_3_0 = False # @param {type:\"boolean\"}\n",
        "animagine_xl_3_1 = False # @param {type:\"boolean\"}\n",
        "animagine_xl_4_0 = False # @param {type:\"boolean\"}\n",
        "heartofapplexl_v20 = False # @param {type:\"boolean\"}\n",
        "heartofapplexl_v30 = False # @param {type:\"boolean\"}\n",
        "holodayo_xl_2_1 = False # @param {type:\"boolean\"}\n",
        "kivotos_xl_2_0 = False # @param {type:\"boolean\"}\n",
        "sd_xl_anime_v52 = False # @param {type:\"boolean\"}\n",
        "kohaku_xl_gamma_rev1 = False # @param {type:\"boolean\"}\n",
        "kohakuxlbeta_beta7 = False # @param {type:\"boolean\"}\n",
        "kohaku_xl_delta_rev1 = False # @param {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev1 = False # @param {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev2 = False # @param {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev3 = False # @param {type:\"boolean\"}\n",
        "kohaku_xl_zeta = False # @param {type:\"boolean\"}\n",
        "starryxlv52_v52 = False # @param {type:\"boolean\"}\n",
        "baxlbartstylexlbluearchiveflatcelluloid_xlv1 = False # @param {type:\"boolean\"}\n",
        "baxlbluearchiveflatcelluloidstyle_xlv3 = False # @param {type:\"boolean\"}\n",
        "ponydiffusionv6xl_v6startwiththisone = False # @param {type:\"boolean\"}\n",
        "pdforanime_v20 = False # @param {type:\"boolean\"}\n",
        "tponynai3_v51weightoptimized = False # @param {type:\"boolean\"}\n",
        "omegaponyxlanime_v20 = False # @param {type:\"boolean\"}\n",
        "illustrious_xl_v0_1 = False # @param {type:\"boolean\"}\n",
        "illustrious_xl_v1_0 = False # @param {type:\"boolean\"}\n",
        "illustrious_xl_v1_1 = False # @param {type:\"boolean\"}\n",
        "illustrious_xl_v2_0_stable = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_earlyaccessversion = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_epsilonpred05version = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_epsilonpred075 = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_epsilonpred077 = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_epsilonpred10version = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_epsilonpred11version = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpredtestversion = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpred05version = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpred06version = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpred065sversion = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpred075sversion = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpred09rversion = False # @param {type:\"boolean\"}\n",
        "noobaixlnaixl_vpred10version = False # @param {type:\"boolean\"}\n",
        "\n",
        "\n",
        "sd_xl_base_1_0_0_9vae and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_base_1.0_0.9vae.safetensors\", \"type\": \"checkpoints\"})\n",
        "animapencilxl_v200 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animaPencilXL_v200.safetensors\", \"type\": \"checkpoints\"})\n",
        "bluepencilxl_v401 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/bluePencilXL_v401.safetensors\", \"type\": \"checkpoints\"})\n",
        "anythingxl_xl and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/AnythingXL_xl.safetensors\", \"type\": \"checkpoints\"})\n",
        "abyssorangexlelse_v10 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/abyssorangeXLElse_v10.safetensors\", \"type\": \"checkpoints\"})\n",
        "counterfeitxl_v1_0 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/CounterfeitXL-V1.0.safetensors\", \"type\": \"checkpoints\"})\n",
        "animeillustdiffusion_v061 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animeIllustDiffusion_v061.safetensors\", \"type\": \"checkpoints\"})\n",
        "nekorayxl_v06w3 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/nekorayxl_v06W3.safetensors\", \"type\": \"checkpoints\"})\n",
        "animagine_xl_3_0 and MODEL_LIST.append({\"url\": \"https://huggingface.co/cagliostrolab/animagine-xl-3.0/resolve/main/animagine-xl-3.0.safetensors\", \"type\": \"checkpoints\"})\n",
        "animagine_xl_3_1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/cagliostrolab/animagine-xl-3.1/resolve/main/animagine-xl-3.1.safetensors\", \"type\": \"checkpoints\"})\n",
        "animagine_xl_4_0 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-4.0.safetensors\", \"type\": \"checkpoints\"})\n",
        "heartofapplexl_v20 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/heartOfAppleXL_v20.safetensors\", \"type\": \"checkpoints\"})\n",
        "heartofapplexl_v30 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/heartOfAppleXL_v30.safetensors\", \"type\": \"checkpoints\"})\n",
        "holodayo_xl_2_1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/holodayo-xl-2.1.safetensors\", \"type\": \"checkpoints\"})\n",
        "kivotos_xl_2_0 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kivotos-xl-2.0.safetensors\", \"type\": \"checkpoints\"})\n",
        "sd_xl_anime_v52 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_anime_V52.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohaku_xl_gamma_rev1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/KBlueLeaf/Kohaku-XL-gamma/resolve/main/kohaku-xl-gamma-rev1.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohakuxlbeta_beta7 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohakuXLBeta_beta7.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohaku_xl_delta_rev1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/KBlueLeaf/Kohaku-XL-Delta/resolve/main/kohaku-xl-delta-rev1.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohaku_xl_epsilon_rev1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/KBlueLeaf/Kohaku-XL-Epsilon/resolve/main/kohaku-xl-epsilon-rev1.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohaku_xl_epsilon_rev2 and MODEL_LIST.append({\"url\": \"https://huggingface.co/KBlueLeaf/Kohaku-XL-Epsilon-rev2/resolve/main/kohaku-xl-epsilon-rev2.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohaku_xl_epsilon_rev3 and MODEL_LIST.append({\"url\": \"https://huggingface.co/KBlueLeaf/Kohaku-XL-Epsilon-rev3/resolve/main/kohaku-xl-epsilon-rev3.safetensors\", \"type\": \"checkpoints\"})\n",
        "kohaku_xl_zeta and MODEL_LIST.append({\"url\": \"https://huggingface.co/KBlueLeaf/Kohaku-XL-Zeta/resolve/main/kohaku-xl-zeta.safetensors\", \"type\": \"checkpoints\"})\n",
        "starryxlv52_v52 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/starryXLV52_v52.safetensors\", \"type\": \"checkpoints\"})\n",
        "baxlbartstylexlbluearchiveflatcelluloid_xlv1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/baxlBartstylexlBlueArchiveFlatCelluloid_xlv1.safetensors\", \"type\": \"checkpoints\"})\n",
        "baxlbluearchiveflatcelluloidstyle_xlv3 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/baxlBlueArchiveFlatCelluloidStyle_xlv3.safetensors\", \"type\": \"checkpoints\"})\n",
        "ponydiffusionv6xl_v6startwiththisone and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/ponyDiffusionV6XL_v6StartWithThisOne.safetensors\", \"type\": \"checkpoints\"})\n",
        "pdforanime_v20 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/pdForAnime_v20.safetensors\", \"type\": \"checkpoints\"})\n",
        "tponynai3_v51weightoptimized and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/tPonynai3_v51WeightOptimized.safetensors\", \"type\": \"checkpoints\"})\n",
        "omegaponyxlanime_v20 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/omegaPonyXLAnime_v20.safetensors\", \"type\": \"checkpoints\"})\n",
        "illustrious_xl_v0_1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v0.1.safetensors\", \"type\": \"checkpoints\"})\n",
        "illustrious_xl_v1_0 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v1.0.safetensors\", \"type\": \"checkpoints\"})\n",
        "illustrious_xl_v1_1 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v1.1.safetensors\", \"type\": \"checkpoints\"})\n",
        "illustrious_xl_v2_0_stable and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v2.0-stable.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_earlyaccessversion and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_earlyAccessVersion.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_epsilonpred05version and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred05Version.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_epsilonpred075 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred075.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_epsilonpred077 and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred077.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_epsilonpred10version and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred10Version.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_epsilonpred11version and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred11Version.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpredtestversion and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPredTestVersion.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpred05version and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred05Version.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpred06version and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred06Version.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpred065sversion and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred065SVersion.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpred075sversion and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred075SVersion.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpred09rversion and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred09RVersion.safetensors\", \"type\": \"checkpoints\"})\n",
        "noobaixlnaixl_vpred10version and MODEL_LIST.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred10Version.safetensors\", \"type\": \"checkpoints\"})\n",
        "\n",
        "##############################\n",
        "fooocus.get_sd_model_from_list(MODEL_LIST)\n",
        "CLEAR_LOG and fooocus.clear_up()\n",
        "logger.info(\"模型下载完成\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "MbpZVvRMPIAC"
      },
      "outputs": [],
      "source": [
        "#@title 👇 自定义模型下载\n",
        "try:\n",
        "    _ = INIT_CONFIG\n",
        "except Exception:\n",
        "    raise Exception(\"未安装 Fooocus\")\n",
        "\n",
        "#@markdown ### 选择模型种类：\n",
        "model_type = \"loras\" # @param [\"checkpoints\", \"loras\", \"embeddings\", \"vae_approx\", \"vae\", \"upscale_models\", \"inpaint\", \"controlnet\", \"clip_vision\", \"prompt_expansion\", \"safety_checker\", \"sam\"]\n",
        "#@markdown ### 填写模型的下载链接：\n",
        "model_url = \"https://huggingface.co/licyk/sd-lora/resolve/main/sdxl/style/CoolFlatColor.safetensors\"  #@param {type:\"string\"}\n",
        "#@markdown ### 填写模型的名称（包括后缀名）：\n",
        "model_name = \"CoolFlatColor.safetensors\"  #@param {type:\"string\"}\n",
        "\n",
        "fooocus.get_sd_model(\n",
        "    url=model_url,\n",
        "    filename=model_name or None,\n",
        "    model_type=model_type,\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "cLB6sKhErcG8"
      },
      "outputs": [],
      "source": [
        "#@title 👇 启动 Fooocus\n",
        "try:\n",
        "    _ = INIT_CONFIG\n",
        "except Exception:\n",
        "    raise Exception(\"未安装 Fooocus\")\n",
        "\n",
        "logger.info(\"启动 Fooocus\")\n",
        "os.chdir(FOOOCUS_PATH)\n",
        "fooocus.check_env(\n",
        "    use_uv=USE_UV,\n",
        "    requirements_file=FOOOCUS_REQUIREMENTS,\n",
        ")\n",
        "fooocus.mount_drive(EXTRA_LINK_DIR)\n",
        "fooocus.tun.start_tunnel(**TUNNEL_PARAMS)\n",
        "logger.info(\"Fooocus 启动参数: %s\", FOOOCUS_LAUNCH_ARGS)\n",
        "!{LAUNCH_CMD}\n",
        "CLEAR_LOG and fooocus.clear_up()\n",
        "logger.info(\"已关闭 Fooocus\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "98sWyzwpXcR8"
      },
      "outputs": [],
      "source": [
        "#@title 👇 文件下载工具\n",
        "\n",
        "#@markdown ### 填写文件的下载链接：\n",
        "url = \"\"  #@param {type:\"string\"}\n",
        "#@markdown ### 填写文件的保存路径：\n",
        "file_path = \"/content\"  #@param {type:\"string\"}\n",
        "#@markdown ### 填写文件的保存名称 (可选)：\n",
        "filename = \"\"  #@param {type:\"string\"}\n",
        "\n",
        "fooocus.download_file(\n",
        "    url=url,\n",
        "    path=file_path or None,\n",
        "    save_name=filename or None,\n",
        ")\n"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
